<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="样区" prop="evaluationSampleArea">
        <el-input
          v-model="queryParams.evaluationSampleArea"
          placeholder="请输入样区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="样本编号" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入样本编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['evaluation:evaluation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['evaluation:evaluation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['evaluation:evaluation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['evaluation:evaluation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="evaluationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="样区" align="center" prop="evaluationSampleArea" />
      <el-table-column label="样本编号" align="center" prop="remark" />
      <el-table-column label="施肥量" align="center" prop="evaluationFertilizationRate" />
      <el-table-column label="干草香" align="center" prop="evaluationHayAroma" />
      <el-table-column label="清甜香" align="center" prop="evaluationSweetAroma" />
      <el-table-column label="焦甜香" align="center" prop="evaluationBurntSweetAroma" />
      <el-table-column label="蜜甜香" align="center" prop="evaluationHoneySweetAroma" />
      <el-table-column label="醇甜香" align="center" prop="evaluationMellowSweetAroma" />
      <el-table-column label="焦香" align="center" prop="evaluationBurntAroma" />
      <el-table-column label="青香" align="center" prop="evaluationGreenAroma" />
      <el-table-column label="烘焙香" align="center" prop="evaluationBakingAroma" />
      <el-table-column label="坚果香" align="center" prop="evaluationNutAroma" />
      <el-table-column label="木香" align="center" prop="evaluationWoodAroma" />
      <el-table-column label="花香" align="center" prop="evaluationFloralAroma" />
      <el-table-column label="香气质" align="center" prop="evaluationAromaQuality" />
      <el-table-column label="香气量" align="center" prop="evaluationAromaVolume" />
      <el-table-column label="透发性" align="center" prop="evaluationPenetrability" />
      <el-table-column label="细腻度" align="center" prop="evaluationFineness" />
      <el-table-column label="柔和感" align="center" prop="evaluationSoftness" />
      <el-table-column label="回甜感" align="center" prop="evaluationSweetAftertaste" />
      <el-table-column label="成团性" align="center" prop="evaluationClumpiness" />
      <el-table-column label="青杂气" align="center" prop="evaluationGreenOffOdor" />
      <el-table-column label="枯焦气" align="center" prop="evaluationBurntOffOdor" />
      <el-table-column label="木质气" align="center" prop="evaluationWoodOffOdor" />
      <el-table-column label="氮杂气" align="center" prop="evaluationNitrogenOffOdor" />
      <el-table-column label="地方性杂气" align="center" prop="evaluationLocalOffOdor" />
      <el-table-column label="干燥感" align="center" prop="evaluationDryness" />
      <el-table-column label="刺激" align="center" prop="evaluationIrritation" />
      <el-table-column label="辣/灼烧" align="center" prop="evaluationSpicyBurning" />
      <el-table-column label="涩/残留" align="center" prop="evaluationAstringentResidue" />
      <el-table-column label="浓度" align="center" prop="evaluationConcentration" />
      <el-table-column label="劲头" align="center" prop="evaluationStrength" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['evaluation:evaluation:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['evaluation:evaluation:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改品吸数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="样区" prop="evaluationSampleArea">
          <el-input v-model="form.evaluationSampleArea" placeholder="请输入样区" />
        </el-form-item>
        <el-form-item label="施肥量" prop="evaluationFertilizationRate">
          <el-input v-model="form.evaluationFertilizationRate" placeholder="请输入施肥量" />
        </el-form-item>
        <el-form-item label="干草香" prop="evaluationHayAroma">
          <el-input v-model="form.evaluationHayAroma" placeholder="请输入干草香" />
        </el-form-item>
        <el-form-item label="清甜香" prop="evaluationSweetAroma">
          <el-input v-model="form.evaluationSweetAroma" placeholder="请输入清甜香" />
        </el-form-item>
        <el-form-item label="焦甜香" prop="evaluationBurntSweetAroma">
          <el-input v-model="form.evaluationBurntSweetAroma" placeholder="请输入焦甜香" />
        </el-form-item>
        <el-form-item label="蜜甜香" prop="evaluationHoneySweetAroma">
          <el-input v-model="form.evaluationHoneySweetAroma" placeholder="请输入蜜甜香" />
        </el-form-item>
        <el-form-item label="醇甜香" prop="evaluationMellowSweetAroma">
          <el-input v-model="form.evaluationMellowSweetAroma" placeholder="请输入醇甜香" />
        </el-form-item>
        <el-form-item label="焦香" prop="evaluationBurntAroma">
          <el-input v-model="form.evaluationBurntAroma" placeholder="请输入焦香" />
        </el-form-item>
        <el-form-item label="青香" prop="evaluationGreenAroma">
          <el-input v-model="form.evaluationGreenAroma" placeholder="请输入青香" />
        </el-form-item>
        <el-form-item label="烘焙香" prop="evaluationBakingAroma">
          <el-input v-model="form.evaluationBakingAroma" placeholder="请输入烘焙香" />
        </el-form-item>
        <el-form-item label="坚果香" prop="evaluationNutAroma">
          <el-input v-model="form.evaluationNutAroma" placeholder="请输入坚果香" />
        </el-form-item>
        <el-form-item label="木香" prop="evaluationWoodAroma">
          <el-input v-model="form.evaluationWoodAroma" placeholder="请输入木香" />
        </el-form-item>
        <el-form-item label="花香" prop="evaluationFloralAroma">
          <el-input v-model="form.evaluationFloralAroma" placeholder="请输入花香" />
        </el-form-item>
        <el-form-item label="香气质" prop="evaluationAromaQuality">
          <el-input v-model="form.evaluationAromaQuality" placeholder="请输入香气质" />
        </el-form-item>
        <el-form-item label="香气量" prop="evaluationAromaVolume">
          <el-input v-model="form.evaluationAromaVolume" placeholder="请输入香气量" />
        </el-form-item>
        <el-form-item label="透发性" prop="evaluationPenetrability">
          <el-input v-model="form.evaluationPenetrability" placeholder="请输入透发性" />
        </el-form-item>
        <el-form-item label="细腻度" prop="evaluationFineness">
          <el-input v-model="form.evaluationFineness" placeholder="请输入细腻度" />
        </el-form-item>
        <el-form-item label="柔和感" prop="evaluationSoftness">
          <el-input v-model="form.evaluationSoftness" placeholder="请输入柔和感" />
        </el-form-item>
        <el-form-item label="回甜感" prop="evaluationSweetAftertaste">
          <el-input v-model="form.evaluationSweetAftertaste" placeholder="请输入回甜感" />
        </el-form-item>
        <el-form-item label="成团性" prop="evaluationClumpiness">
          <el-input v-model="form.evaluationClumpiness" placeholder="请输入成团性" />
        </el-form-item>
        <el-form-item label="青杂气" prop="evaluationGreenOffOdor">
          <el-input v-model="form.evaluationGreenOffOdor" placeholder="请输入青杂气" />
        </el-form-item>
        <el-form-item label="枯焦气" prop="evaluationBurntOffOdor">
          <el-input v-model="form.evaluationBurntOffOdor" placeholder="请输入枯焦气" />
        </el-form-item>
        <el-form-item label="木质气" prop="evaluationWoodOffOdor">
          <el-input v-model="form.evaluationWoodOffOdor" placeholder="请输入木质气" />
        </el-form-item>
        <el-form-item label="氮杂气" prop="evaluationNitrogenOffOdor">
          <el-input v-model="form.evaluationNitrogenOffOdor" placeholder="请输入氮杂气" />
        </el-form-item>
        <el-form-item label="地方性杂气" prop="evaluationLocalOffOdor">
          <el-input v-model="form.evaluationLocalOffOdor" placeholder="请输入地方性杂气" />
        </el-form-item>
        <el-form-item label="干燥感" prop="evaluationDryness">
          <el-input v-model="form.evaluationDryness" placeholder="请输入干燥感" />
        </el-form-item>
        <el-form-item label="刺激" prop="evaluationIrritation">
          <el-input v-model="form.evaluationIrritation" placeholder="请输入刺激" />
        </el-form-item>
        <el-form-item label="辣/灼烧" prop="evaluationSpicyBurning">
          <el-input v-model="form.evaluationSpicyBurning" placeholder="请输入辣/灼烧" />
        </el-form-item>
        <el-form-item label="涩/残留" prop="evaluationAstringentResidue">
          <el-input v-model="form.evaluationAstringentResidue" placeholder="请输入涩/残留" />
        </el-form-item>
        <el-form-item label="浓度" prop="evaluationConcentration">
          <el-input v-model="form.evaluationConcentration" placeholder="请输入浓度" />
        </el-form-item>
        <el-form-item label="劲头" prop="evaluationStrength">
          <el-input v-model="form.evaluationStrength" placeholder="请输入劲头" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEvaluation, getEvaluation, delEvaluation, addEvaluation, updateEvaluation } from "@/api/evaluation/evaluation";

export default {
  name: "Evaluation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 品吸数据表格数据
      evaluationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        evaluationSampleArea: null,
        createTime: null,
        remark: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        evaluationSampleArea: [
          { required: true, message: "样区不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询品吸数据列表 */
    getList() {
      this.loading = true;
      listEvaluation(this.queryParams).then(response => {
        this.evaluationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        evaluationSampleArea: null,
        evaluationFertilizationRate: null,
        evaluationHayAroma: null,
        evaluationSweetAroma: null,
        evaluationBurntSweetAroma: null,
        evaluationHoneySweetAroma: null,
        evaluationMellowSweetAroma: null,
        evaluationBurntAroma: null,
        evaluationGreenAroma: null,
        evaluationBakingAroma: null,
        evaluationNutAroma: null,
        evaluationWoodAroma: null,
        evaluationFloralAroma: null,
        evaluationAromaQuality: null,
        evaluationAromaVolume: null,
        evaluationPenetrability: null,
        evaluationFineness: null,
        evaluationSoftness: null,
        evaluationSweetAftertaste: null,
        evaluationClumpiness: null,
        evaluationGreenOffOdor: null,
        evaluationBurntOffOdor: null,
        evaluationWoodOffOdor: null,
        evaluationNitrogenOffOdor: null,
        evaluationLocalOffOdor: null,
        evaluationDryness: null,
        evaluationIrritation: null,
        evaluationSpicyBurning: null,
        evaluationAstringentResidue: null,
        evaluationConcentration: null,
        evaluationStrength: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加品吸数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEvaluation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改品吸数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEvaluation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEvaluation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除品吸数据编号为"' + ids + '"的数据项？').then(function() {
        return delEvaluation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('evaluation/evaluation/export', {
        ...this.queryParams
      }, `evaluation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
